//
//  JiaoXueCeShiCollectionView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/5/9.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "JiaoXueCeShiCollectionView.h"
#import "TWorkListVC.h"
#define CellSP 20*fw
#define CellW 50*fw


#import "KeChengNectVC.h"

@interface JiaoXueCeShiCollectionView ()<TestSelectedTopViewDelegate>
{
    TWorkListVC *workListView;
    BOOL Type;
}

@end

@implementation JiaoXueCeShiCollectionView

- (TestTopNavView *)testTopView{
    if (!_testTopView) {
        TestTopNavView *topView = [[TestTopNavView alloc]init];
        topView.frame = CGRectMake(0, 0, 875*fw, 44);
        topView.delegate = self;
        _testTopView = topView;
    }
    return _testTopView;
}
- (UILabel *)noDataLabel{
    if (!_noDataLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"当前数据为空";
        label.textAlignment = 1;
        _noDataLabel = label;
    }
    return _noDataLabel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    Type = NO;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(showView) name:@"ShowView" object:nil];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.testTopView];
    [_testTopView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.equalTo(@0);
       make.right.equalTo(@0);
       make.top.equalTo(@0);
       make.height.equalTo(@44);
    }];
    
    self.view.backgroundColor = MAINBACKCOLOR;

    [self.collectionView registerClass:[TCollectionViewCell class] forCellWithReuseIdentifier:@"TCollectionViewCell"];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView:) name:@"ChangeCellSpaNotice" object:nil];
    // Do any additional setup after loading the view.
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.top.equalTo(@44);
        make.right.equalTo(@0);
        make.bottom.equalTo(@0).offset(-20);
    }];
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.testTopView];
    [self.testTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    [self.view addSubview:self.noDataLabel];
    [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@44);
        make.bottom.equalTo(@0);
    }];
    
}
- (void)showView{
    self.collectionView.hidden = NO;
}
- (void)changeView:(NSNotification *)info{
    BOOL type = [[info.userInfo objectForKey:@"Type"] intValue];
    Type = type;
//    if (type == YES) {
//        Type = NO;
//    }else{
//        Type = YES;
//    }
    [self.collectionView reloadData];
}
- (void)leftButtonClick{
    [CJYearMonthSelectedView showDatePickerWithTitle:@"选择月份" minDateStr:@"2000-01" resultBlock:^(NSString *selectValue) {
        //选择完成后的操作
        NSLog(@"selected month is %@", selectValue);
    }];
}
- (void)leftTestButtonClick{
    [CJYearMonthSelectedView showDatePickerWithTitle:@"选择月份" minDateStr:@"2000-01" resultBlock:^(NSString *selectValue) {
        //选择完成后的操作
        NSLog(@"selected month is %@", selectValue);
    }];
}
#pragma mark - 弹出选择班级的alert
- (void)rightTestButtonClick{
    [CJClassSelectedView showDatePickerWithTitle:@"选择班级" minDateStr:@"11" resultBlock:^(TeacherClassListModel * _Nonnull selectValue) {
        NSLog(@"选中的模型 %@",selectValue);
    }];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TCollectionViewCell" forIndexPath:indexPath];
    cell.titleLabel.text = @"慧阅读2-2C Lesson 25";
    return cell;
}
#pragma mark == collectionViewDelegate
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(204*fw, 105*fh);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    //top, left, bottom, right
    if (Type == YES) {
        return UIEdgeInsetsMake(CellSP, CellSP, CellSP,CellSP);
    }else{
        return UIEdgeInsetsMake(CellSP, CellW, CellSP,CellW);
    }
    
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return CellSP;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return CellSP;
}

//是否允许移动Item
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(9_0)
{
    return YES;
}
//移动Item时触发的方法
- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath NS_AVAILABLE_IOS(9_0);
{
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [PublickFunctionObject changeMainView:@"TeachChangeNotice" AndType:Type];
    
}
#pragma mark <UICollectionViewDelegate>

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}


// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    
}
- (void)getDataForView:(NSString *)name{
    [self.collectionView reloadData];
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"ShowView" object:nil];
}

@end
